Skip to content

Fix LaTeX math mode in adjustbox - wrap formula in $...$#48

Closed
bdtran2002 wants to merge 2 commits intomainfrom
fix/latex-math-mode
Closed

Fix LaTeX math mode in adjustbox - wrap formula in $...$#48
bdtran2002 wants to merge 2 commits intomainfrom
fix/latex-math-mode

Conversation

@bdtran2002
Copy link
Copy Markdown
Contributor

This pull request makes a small change to the LaTeX rendering logic for formulas in the build_latex_for_formulas function. The main update is to ensure that formulas are wrapped in $... math mode delimiters when rendered inside the \adjustbox` command, which improves LaTeX formatting and compatibility.

LaTeX rendering improvement:

  • Updated the formula rendering line in build_latex_for_formulas (in latex_utils.py) to wrap formulas with $... inside \adjustbox`, ensuring proper math mode handling.

Copilot AI review requested due to automatic review settings April 9, 2026 18:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the LaTeX generation in build_latex_for_formulas to ensure formulas rendered inside \adjustbox are explicitly wrapped in math mode delimiters, improving LaTeX compatibility when scaling equations.

Changes:

  • Wrap formula content inside \adjustbox{...}{...} with $...$ to force math mode.
  • Adjust the formula rendering line used for non-“special class” formulas.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

escaped_name = name.replace("\\", "\\textbackslash ").replace("&", "\\&").replace("%", "\\%").replace("#", "\\#").replace("_", "\\_").replace("^", "\\textasciicircum ").replace("{", "\\{").replace("}", "\\}")
body_lines.append("\\textbf{" + escaped_name + "}")
body_lines.append("\\[ \\adjustbox{max width=\\linewidth}{\\displaystyle " + latex + "} \\]")
body_lines.append("\\[ \\adjustbox{max width=\\linewidth}{$" + latex + "$} \\]")
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapping the formula in $...$ inside \adjustbox forces textstyle math, so fractions/summations will render smaller than intended even though the outer environment is display math (\[ ... \]). To preserve the previous display-style rendering, include \displaystyle inside the math delimiters (e.g., {$\displaystyle ...$}) or use an equivalent display-style wrapper inside the adjustbox content.

Copilot uses AI. Check for mistakes.
escaped_name = name.replace("\\", "\\textbackslash ").replace("&", "\\&").replace("%", "\\%").replace("#", "\\#").replace("_", "\\_").replace("^", "\\textasciicircum ").replace("{", "\\{").replace("}", "\\}")
body_lines.append("\\textbf{" + escaped_name + "}")
body_lines.append("\\[ \\adjustbox{max width=\\linewidth}{\\displaystyle " + latex + "} \\]")
body_lines.append("\\[ \\adjustbox{max width=\\linewidth}{$" + latex + "$} \\]")
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the LaTeX emitted by the generate-sheet endpoint but there are currently no tests asserting the \adjustbox{...}{...} formula wrapping. Adding a regression test that checks the generated TeX contains the expected math-mode wrapper (and \displaystyle if kept) would prevent future formatting/compilation regressions.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied both changes in commit ebd0868:

  1. latex_utils.py: Changed $...$ back to $\displaystyle ...$ inside \adjustbox, so fractions/summations render at display size rather than the smaller text-style.
  2. tests.py: Added test_generate_sheet_formula_uses_displaystyle_in_adjustbox which asserts the generated TeX contains both \adjustbox{max width=\linewidth} and $\displaystyle.

@bdtran2002 bdtran2002 closed this Apr 9, 2026
@bdtran2002 bdtran2002 deleted the fix/latex-math-mode branch April 9, 2026 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants